package com.secxiot.consumer.user.controller;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import com.secxiot.common.constant.ServerStatusEnum;
import com.secxiot.common.entity.ResultVo;
import com.secxiot.common.exception.BaseException;
import com.secxiot.common.utils.JSMSUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "短消息模块")
@RequestMapping("message")
@RestController
public class MessageController {

    @ApiOperation(value = "获取验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String")
    })
    @GetMapping
    public ResultVo<String> getUser(@RequestParam(value = "mobile", required = true) String mobile) throws APIConnectionException, APIRequestException, BaseException {
        String msId = JSMSUtil.sendSMSCode(mobile);
        if (StringUtils.isNotBlank(msId)) {
            return new ResultVo<>(msId);
        } else {
            return new ResultVo<>(ServerStatusEnum.VALID_SMS_CODE_ERROR);
        }
    }
}
